#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os, sys
import ConfigParser
import socket
import urllib




def walkList(t_dir):
    i_list = []
    for item in os.listdir(t_dir):
        if os.path.isdir(item):
            continue
        else:
            i_list.append(item)
    return  i_list

def readIni():
    i_config = os.path.join(sys.path[0] ,"path.config")
    ini_parser = ConfigParser.ConfigParser()
    ini_parser.read(i_config)
    return ini_parser.items("path")

def generatorMap():
    i_dict = {}
    path_list = readIni()
    host_ip = get_ip_address()
    for item in path_list:
        i_key = item[0]
        i_path = item[1]
        file_list = walkList(i_path)
        for itor in file_list:
            i_item = urllib.quote(itor.decode("GBK").encode("utf-8"))
            i_url = u"rtsp://%s/%s/%s"%(host_ip.decode("GBK") , i_key.decode("GBK") , i_item)
            i_dict[itor.decode("GBK")] = i_url
    return  i_dict



def get_ip_address():
    s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
    s.connect(("baidu.com", 80))
    return s.getsockname()[0]



if __name__ == "__main__":
    # i_list = readIni()
    # i_dict = generatorMap()
    # for key ,value in i_dict.iteritems():
    #     print key  ,  value
    i_url = u"this is a 中文 /%$#@*()"
    print urllib.quote(i_url.encode("utf-8"))





